package com.durablemethods.futures.server;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.durablemethods.futures.client.NHLTradeEntryDto;

public class TradesServlet extends HttpServlet {
	private static final long serialVersionUID = -3952934203702273259L;
	StaticTradeService service = new StaticTradeService();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<NHLTradeEntryDto> trades = service.getTrades();
		resp.getWriter().println("Buys,Sells,Team,Quanity, Price,Timestamp");
		String parameter = req.getParameter("trader");
		for (NHLTradeEntryDto trade : trades) {
			String format = String.format("%s,%s,%s,%s,%s,%s", trade.getBuyer().getAlias(), trade.getSeller().getAlias(), trade.getTeamId(),trade.getShares(),trade.getPrice(), trade.getTransactionDate() );
			if(parameter== null || trade.getBuyer().getGoogleAccount().equalsIgnoreCase(parameter) || trade.getSeller().getGoogleAccount().equalsIgnoreCase(parameter)){
				resp.getWriter().println(format);
			}
		}
	}

}
